home *** CD-ROM | disk | FTP | other *** search
- /* DoListSCSIDevices.c */
- /*
- * DoListSCSIDevices.c
- * Copyright © 1992-94 Apple Computer Inc. All Rights Reserved.
- *
- * Find all SCSI devices. The alogrithm first asks the SCSI Manager for the
- * number of busses, then loops through each bus for each device and LUN.
- * old SCSI Manager.
- */
- #include "SCSISimpleSample.h"
- /*
- * Note: if you are running on a Quadra 840-AV with a CD300, this will hang the
- * Macintosh if it tries to access LUN 1 when calling the asynchronous SCSI
- * Manager. You have to enable > 0 logical units in the Test Menu. This bug was
- * fixed in the SCSI Manager Extension (4.3f1) and in the PowerPC ROMs.
- */
-
- void
- DoListSCSIDevices(void)
- {
- OSErr status;
- unsigned short lastHostBus;
- unsigned short initiatorID;
- unsigned short bus;
- unsigned short targetID;
- unsigned short LUN;
- DeviceIdent scsiDevice;
- SCSIGetVirtualIDInfoPB scsiGetVirtualIDInfo;
- short deviceCount;
- Str255 work;
-
- LOG("\pList all SCSI Devices");
- deviceCount = 0;
- /*
- * If we have the asynchronous SCSI Manager, find out how many busses
- * are present on this system. If not, force a "single bus" scan, since
- * DoSCSICommandWithSense ignores the hostBus information if it is
- * forced into "old-style" calls.
- */
- if (gEnableNewSCSIManager)
- status = SCSIGetHighHostBusAdaptor(&lastHostBus);
- else {
- status = noErr;
- lastHostBus = 0; /* Force one bus only */
- }
- if (status == noErr) {
- for (bus = 0; bus <= lastHostBus; bus++) {
- /*
- * Look at this SCSI bus. This would be a good place to allocate
- * the SCSIExecIO command block. In this sample, however, it's
- * allocated on each call to AsyncSCSI which is inefficient.
- * Note that it is possible to have busses with no devices.
- * For example, if a system has a built-in internal and external
- * SCSI Bus (such as the Quadra 950 or PowerMac 8100), a third-
- * party bus adaptor that supports the asynchronous SCSI Manager
- * would be assigned bus 2 (with busses 0 and 1 referencing the
- * internal system busses). In this case, a system could have
- * no devices on bus 0 or 1.
- */
- *((long *) &scsiDevice) = 0;
- scsiDevice.bus = bus;
- status = SCSIGetInitiatorID(scsiDevice, &initiatorID);
- if (status != noErr)
- continue;
- /*
- * SCSIGetInitiatorID returned the bus ID of the Macintosh.
- * This is almost always seven, but only the SCSI Manager
- * knows for sure. Note that, by getting the Macintosh
- * bus ID dynamically, we prepare the code for a future
- * system that permitted more than one Macintosh on the
- * same SCSI bus.
- */
- for (targetID = 0; targetID <= 7; targetID++) {
- if (targetID == initiatorID)
- continue;
- scsiDevice.targetID = targetID;
- for (LUN = 0; LUN <= gMaxLogicalUnit; LUN++) {
- /*
- * Try to send a command to this LUN. If it fails, don't
- * try for higher-valued LUNs. SCSICheckForDevicePresent
- * looks, carefully, at the returned error to distinguish
- * between missing devices and devices that are present,
- * but unable to respond, such as CD-ROM players with
- * no disk inserted. This call to SCSICheckForDevicePresent
- * will use the asynchronous SCSI Manager if it can.
- */
- scsiDevice.LUN = LUN;
- if (SCSICheckForDevicePresent(scsiDevice, TRUE) == FALSE)
- break; /* Don't look for LUNs */
- else {
- ++deviceCount; /* Found a device */
- DoGetDriveInfo(scsiDevice, TRUE); /* no intro msg */
- } /* Check status */
- } /* LUN loop */
- } /* Target loop */
- } /* Bus loop */
- /*
- * Now, we need to look at the hard-wired SCSI drive addresses and
- * check whether a third-party hardware interface that does not use
- * the asynchronous SCSI Manager recognizes this address.
- */
- scsiDevice.bus = 0;
- for (targetID = 0; targetID <= 6; targetID++) {
- CLEAR(scsiGetVirtualIDInfo);
- scsiGetVirtualIDInfo.scsiPBLength = sizeof scsiGetVirtualIDInfo;
- scsiGetVirtualIDInfo.scsiOldCallID = targetID;
- status = SCSIAction((SCSI_PB *) &scsiGetVirtualIDInfo);
- if (status != noErr) {
- /*
- * The asynchronous SCSI Manager does not know about this
- * target ID. Check whether it exists (forcing the request
- * to use the original SCSI Manager).
- */
- scsiDevice.targetID = targetID;
- for (LUN = 0; LUN <= gMaxLogicalUnit; LUN++) {
- scsiDevice.LUN = LUN;
- if (SCSICheckForDevicePresent(scsiDevice, FALSE) == FALSE)
- break; /* Don't look for LUNs */
- else {
- ++deviceCount; /* Found a device */
- DoGetDriveInfo(scsiDevice, TRUE); /* no intro msg */
- } /* Check status */
- }
- }
- }
- } /* Found a host adaptor */
- NumToString(deviceCount, work);
- AppendPascalString(work, "\p SCSI Devices");
- LOG(work);
- }
-
-